import {redisDataSource} from '../config/redisDataSource.js'

const {REDIS_DEFAULT_EXPIRE, REDIS_CAPTCHA_EXPIRE, REDIS_TOKEN_EXPIRE, REDIS_CAPTCHA_PREFIX, REDIS_TOKEN_PREFIX} = process.env

/**
 * @author: ares
 * @date: 2025/7/4 上午9:15
 * @description: 通用设置redis值
 * @param key
 * @param value
 * @param expire
 */
export function setRedisData(key: string|number, value: any, expire = Number(REDIS_DEFAULT_EXPIRE)) {
	return redisDataSource.set(key.toString(), value, {
        EX: expire
    })
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:16
 * @description: 通用获取redis值
 * @param key
 */
export function getRedisData(key: string|number) {
	return redisDataSource.get(key.toString())
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:16
 * @description: 通用删除redis值
 * @param key
 */
export function removeRedisData(key: string|number) {
	return redisDataSource.del(key.toString())
}

/**
 * @author: ares
 * @date: 2025/7/4 上午9:16
 * @description: 设置redis验证码
 * @param key
 * @param value
 * @param expire
 */
export function setRedisCaptchaData(key: string|number, value: any, expire = Number(REDIS_CAPTCHA_EXPIRE)) {
	return redisDataSource.set(`${REDIS_CAPTCHA_PREFIX}${key}`, value, {
		EX: expire
	})
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:17
 * @description: 获取redis验证码
 * @param key
 */
export function getRedisCaptchaData(key: string|number) {
	return redisDataSource.get(`${REDIS_CAPTCHA_PREFIX}${key}`)
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:17
 * @description: 删除redis验证码
 * @param key
 */
export function removeRedisCaptchaData(key: string|number) {
	return redisDataSource.del(`${REDIS_CAPTCHA_PREFIX}${key}`)
}

/**
 * @author: ares
 * @date: 2025/7/4 上午9:17
 * @description: 设置redis token
 * @param key
 * @param value
 * @param expire
 */
export function setRedisTokenData(key: string|number, value: any, expire = Number(REDIS_TOKEN_EXPIRE)) {
	return redisDataSource.set(`${REDIS_TOKEN_PREFIX}${key}`, value, {
		EX: expire
	})
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:17
 * @description: 获取redis token
 * @param key
 */
export function getRedisTokenData(key: string|number) {
	return redisDataSource.get(`${REDIS_TOKEN_PREFIX}${key}`)
}
/**
 * @author: ares
 * @date: 2025/7/4 上午9:17
 * @description: 删除redis token
 * @param key
 */
export function removeRedisTokenData(key: string|number) {
	return redisDataSource.del(`${REDIS_TOKEN_PREFIX}${key}`)
}
